package com.gzy.rpsm.property.mapper;

import com.github.pagehelper.Page;
import com.gzy.rpsm.property.pojo.UnpaidOwner;
import com.gzy.rpsm.property.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper {

    Page<User> owners();

    @Select("select userid,username,account,idcard,gender,age,user_type,user_status,user_roomid from user where account = #{account} and password = #{password} and user_type = 3")
    User queryByAccountAndPassword(String account, String password);

    // 工单字段少了最后的#{user_avatar}
    @Insert("insert into user value (NULL,#{account},#{password},#{idcard},#{username},#{gender},#{age},#{user_type},#{user_status},#{user_roomid},#{user_avatar})")
    int insertUser(User user);

    @Update("update user set user_status = #{user_status} where userid = #{userid}")
    int changeUserStatus(User user);

    @Select("select userid,username,account,idcard,gender,age,user_type,user_status,user_roomid from user where userid = #{id}")
    User queryById(int id);

    @Select("select a.amount_date,a.amount,`user`.userid,`user`.username,room.room_code from " +
            "(select * from amount where amount.isPaid = 2 and amount.amount_type =#{typeId}) as a " +
            "left join room on a.amount_roomid = room.room_id " +
            "left join user on room.room_id =`user`.user_roomid order by a.amount_date asc ,`user`.username")
    @ResultMap("com.gzy.rpsm.property.mapper.UserMapper.unpaidOwner")
    Page<UnpaidOwner> unpaidOwnerList(Integer typeId);
}